'use strict';
var userId;
angular.module('Hospital.four', ['ngRoute', 'Hospital.services'])

.config(['$routeProvider', function($routeProvider) {
	console.log($routeProvider);
	$routeProvider.when('/four', {
		templateUrl: 'views/four/four.html'
	});		
}])
.controller('showResourceCtrl', ['$location', '$http', '$scope', function($location, $http, $scope) {
	$scope.params = Object.create($scope.config.defaultPageInfo);
	
	$scope.params.messageStatus = 0;
	$scope.params.userId=1;
	$scope.resourceStatusMap={
			'1':{"value":"移除","css":"label-warning"},
			'0':{"value":"添加","css":"label-success"}
	};
	$http.post(API_SERVER + 'user/list', $scope.params).success(function(res) {
		console.log(res);
		if (res && res.code === 0) {
			$scope.userList = res.dataList;
		
		}
	});
	$scope.getUser=function(user){
		
			$scope.params.userId=user.Id;
		$scope.getPage();
	}
	
	$scope.editResource=function(resource){
		$scope.params.resourceId=resource.Id;
		$scope.params.linkFlag=resource.linkFlag;
			//移除
			$http.post(API_SERVER + 'resource/edit', $scope.params).success(function(res) {
				console.log(res);
				if (res && res.code === 0) {
					alert("修改 成功");
					
					$scope.getPage();
				}
			});
		
	}
	
	
	$scope.getPage = function(pn) {
		if(!isNaN(pn)) {
			if($scope.params.pn === pn || pn <=0 || pn > $scope.params.pc) {
				return;
			}
			$scope.params.pn = pn;
		}
		$http.post(API_SERVER + 'resource/list', $scope.params).success(function(res) {
			console.log(res);
			if (res && res.code === 0) {
				$scope.params.pn =res.pageNo;
				$scope.params.pc = res.pageCnt;
				$scope.resourceList = res.dataList;
				
			}
		});
	};
	$scope.getPage();
	
	



	
	
	
}]);

$(function(){
	 $(".nav-tabs>li").click(function(){
	        var num = $(this).index();
	       $(".tab-content>div").removeClass("active");
	       var e=$(".tab-content>div").eq(num);
	       e.addClass("active");
	   });
	    $('#tags_1').tagsInput();
});
